<?php
function child($rows,$id){
	$childs=array();
	foreach($rows as $key=>$value){
	    if($value['parent']==$id){
	       $childs[$value['id']]=$value;
	    }
	}
	return $childs;
}
function build(&$rows,$id=0){
	$childs=child($rows,$id);
	if(empty($childs)){
	      return null;
	}
	foreach($childs as $key=>$value){
	    $rescurTree=build($rows,$value['id']);
	    if(null!=$rescurTree){
	       $childs[$key]['child']=$rescurTree;
	    }
	}
	return $childs;
}
function json($output){
	header('Content-Type:text/plain');
	echo json_encode($output);
}
?>